<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const minCostClimbingStairs = cost => {
      const getSum = (index, length, ans) => {
        for (let i = index; i < length; i++) {
          if (cost[i + 1] <= cost[i] + cost[i - 1]) {
            ans += cost[i + 1]
          } else {
            ans += cost[i]
          }
          console.log(ans);
        }
        return ans
      }
      let sum = 0
      if (2 * cost[0] < cost[1]) {
        sum = cost[0]
        getSum(1, cost.length, sum)
      } else {
        sum = cost[1]
        getSum(2, cost.length, sum)
      }
      return sum
    }

    console.log(minCostClimbingStairs([1, 100, 1, 1, 1, 100, 1, 1, 100, 1]));
  </script>
</body>

</html>